/**
 * @Date 2023-02-21 10:03:49
 * @Remark
 */

// react
import React from "react";
// lib
import { Space, Button, Popconfirm, Switch } from "antd";
// components & widget
// style
// config
// import { MODULE_NAME } from "./config";
// script & methods & public
// store

import { state } from "./state";
// import { render } from "react-dom";
import { delBook } from "./controller";
import { dictState } from "state/global";
// controller
// interface
// 其它

const TableColumns = [
  {
    title: "图书ID",
    dataIndex: "bookId",
  },
  {
    title: "图书名称",
    dataIndex: "title",
  },
  {
    title: "作者",
    dataIndex: "author",
  },
  {
    title: "出版社",
    dataIndex: "publisher",
  },
  {
    title: "出版日期",
    dataIndex: "publishDate",
  },
  {
    title: "所属分类",
    dataIndex: "categoryId",
    render:(el:number) =>{
      return  state.getCategoryList().find(item => item.categoryId === el)?.categoryName
    }
  },
  {
    title: "ISBN",
    dataIndex: "isbn",
  },
  {
    title: "定价",
    dataIndex: "price",
  },
  {
    title: "可借数量",
    dataIndex: "availableCount",
  },
  {
    title: "状态",
    dataIndex: "status",
    render: (el:string) => dictState.BookStatusList.find(item => item.code === el)?.name
  },
  {
    title: "操作",
    key: "action",
    fixed: "right" as any,
    render: (el: BookDto) => {
      const edit = async (disable = false) => {
        state.disable = disable;
        state.editModal = el
      };
      const del = () => {
        delBook(el.bookId);
      };

      return (
        <Space>
          {/* <Button
            size="small"
            type="primary"
            ghost
            onClick={() => {
              edit(true);
            }}
          >
            详情
          </Button> */}
          <Button
            size="small"
            type="primary"
            ghost
            onClick={() => {
              edit();
            }}
          >
            编辑
          </Button>
          <Popconfirm
            title={`确定删除《${el.title}》?`}
            onConfirm={del}
          >
            <Button size="small" danger ghost>
              删除
            </Button>
          </Popconfirm>
        </Space>
      );
    },
  },
];

export default TableColumns;
